package com.myown.algorithm;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 集合工具类 <p>
 *
 * @author lincky
 * @version v1.0.0
 * @time 2017.02.21 15:33
 */
public class CollectionUtil {


    /**
     * <tt>List</tt>集合求和 <p>
     *
     * @param list 数组
     * @return <tt>list</tt>从<tt>low</tt>至<tt>high</tt>之和
     */
    public static <T extends Number> double sum(List<T> list) {
        return sum(list, 0, list.size() - 1);
    }

    /**
     * <tt>List</tt>集合求和 <p>
     *
     * @param list 数组
     * @param low  起始索引
     * @param high 终止索引
     * @return <tt>list</tt>从<tt>low</tt>至<tt>high</tt>之和
     */
    public static <T extends Number> double sum(List<T> list,
                             int low,
                             int high) {
        double sum = 0;
        for (int i = low; i <= high; i++) {
            sum += list.get(i).doubleValue();
        }
        return sum;
    }

    /*
        test
     */
    public static void main(String[] args) {
    }

}
